﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author YUga studio
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.invoicing.dao;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.oplink.webbase.common.persistence.BaseDao;
import com.oplink.webbase.common.persistence.BaseDaoImpl;
import com.oplink.webbase.modules.invoicing.entity.Stock;
import com.oplink.webbase.modules.invoicing.entity.SubStock;

/**
 * 告警DAO接口
 * 
 * @author YUga studio
 * @version 2015-01-12
 */
public interface StockDao extends StockDaoCustom, CrudRepository<Stock, Long> {

	@Modifying
	@Query("update Stock set delFlag='" + Stock.DEL_FLAG_DELETE + "' where id = ?1")
	public int deleteById(Long id);

	@Query("select count(*) from Stock s1,SubStock s2 " + "where  s1.stockFormId = s2.stockFormId and s2.goodsId = ?1 "
			+ "and s1.delFlag='" + Stock.DEL_FLAG_NORMAL + "'" + "and s2.delFlag='" + Stock.DEL_FLAG_NORMAL + "'")
	public int isExistGoods(String gid);

	@Query("from SubStock  where  goodsId = ?1 and delFlag='" + Stock.DEL_FLAG_NORMAL + "'")
	public SubStock getSubStock(String gid);
}

/**
 * DAO自定义接口
 * 
 * @author YUga studio
 */
interface StockDaoCustom extends BaseDao<Stock> {

}

/**
 * DAO自定义接口实现
 * 
 * @author YUga studio
 */
@Component
class StockDaoImpl extends BaseDaoImpl<Stock> implements StockDaoCustom {

}